const path = require('path')
const TerserPlugin = require('terser-webpack-plugin')
const CopyPlugin = require("copy-webpack-plugin");
const { CleanWebpackPlugin } = require('clean-webpack-plugin')

function resolve(dir) {
  return path.join(__dirname, dir)
}

module.exports = {
  mode: 'production',
  entry: {
    'video-frame-capture.min': './src/index.js',
  },
  output: {
    filename: '[name].js',
    library: {
      name: "videoFrameCapture",
      type: "umd"
    },
    path: resolve('dist')
  },
  module: {
    rules: [
      {
        test: /\.(js)$/,
        exclude: /node_modules/,
        use: ['babel-loader']
      },
      {
        test: /\.worker\.(c|m)?js$/,
        exclude: /node_modules/,
        use: [
          {
            loader: 'worker-loader',
            options: {
              publicPath: '/',
              inline: 'no-fallback'
            }
          },
        ]
      }
    ]
  },
  optimization: {
    // minimize: true,
    // minimizer: [
    //   // 使用压缩插件
    //   new TerserPlugin({})
    // ]
  },
  // webpack.config.js
  resolve: {
    // 1.不需要node polyfilss
    alias: {
      crypto: false
    }
  },
  plugins: [
    new CleanWebpackPlugin(),
    new CopyPlugin({
      patterns: [
        { from: "package.json", to: "package.json" },
        { from: "readme.md", to: "readme.md" }
      ],
    })
  ]
}